use crate::core::error::ParrotError;
use snafu::prelude::*;
use std::sync::Arc;

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum ConvertError {
    #[snafu(display("Failed to convert u32 {value} to usize"))]
    U32ToUSize {
        value: u32,
        source: <usize as TryFrom<u32>>::Error,
    },

    #[snafu(display("Failed to convert usize {value} to u32"))]
    USizeToU32 {
        value: usize,
        source: <u32 as TryFrom<usize>>::Error,
    },

    #[snafu(display("Failed to convert usize {value} to u64"))]
    USizeToU64 {
        value: usize,
        source: <u64 as TryFrom<usize>>::Error,
    },

    #[snafu(display("Failed to convert i32 {value} to enum type {type_name}"))]
    I32ToEnum { type_name: String, value: i32 },

    #[snafu(display("Failed to convert string {value} to enum type {type_name}"))]
    StringToEnum { type_name: String, value: String },

    #[snafu(display("Can not convert str {path} to PathBuf"))]
    StrToPathBuf {
        path: String,
        source: core::convert::Infallible,
    },

    #[snafu(display("Can not parse {uri} to Uri"))]
    StrToUri {
        uri: String,
        #[snafu(source(from(http::uri::InvalidUri, Arc::new)))]
        source: Arc<http::uri::InvalidUri>,
    },
}

impl From<ConvertError> for ParrotError {
    fn from(source: ConvertError) -> Self {
        ParrotError::Convert { source }
    }
}
